package com.drore.logapp.http;

import com.drore.logapp.http.interceptor.HttpInterceptor;
import com.drore.logapp.http.converter.GsonConverterFactory;
import com.drore.logapp.utils.GlobalConfig;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;


/**
 * Created by YaNan
 * on 2017/3/29 0029.
 */

public class HttpTokenLogin {
    private static HttpApi httpApi;
    private static String TAG = "HttpTokenLogin";

    public static HttpApi createHttpClient() {
        if (httpApi == null) {
            OkHttpClient client = new OkHttpClient.Builder()
                    .addInterceptor(new HttpInterceptor())
                    .readTimeout(15, TimeUnit.SECONDS)
                    .connectTimeout(15, TimeUnit.SECONDS)
                    .addInterceptor(new HttpInterceptor())
                    .build();
            httpApi = new Retrofit
                    .Builder()
                    .client(client)
                    .baseUrl(GlobalConfig.BASE_URL)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build()
                    .create(HttpApi.class);
        }
        return httpApi;
    }
}
